package com.guhappy.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class HibernateListener implements ServletContextListener {

	private static Class<HibernateListener> clazz = HibernateListener.class;

	public static final String KEY_NAME = clazz.getName();

	public void contextDestroyed(ServletContextEvent event) {
	}

	public void contextInitialized(ServletContextEvent event) {

		try {

			// save the Hibernate session factory into serlvet context
			event.getServletContext().setAttribute(KEY_NAME,
					HibernateUtil.getSessionFactory());

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}
}